unit GMedIlgis;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, GForm, cxGraphics, cxPropertiesStore, dxBarExtItems, dxBar,
  cxClasses, ActnList, dxStatusBar, cxControls, cxPC, cxStyles, cxCustomData,
  cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridCustomView,
  cxGrid, cxNavigator, cxDBNavigator, cxContainer, cxGroupBox, cxCalc,
  cxLookAndFeelPainters, impexp;

type
  TfMedIlgis = class(TGamaForm)
    tsSarasas: TcxTabSheet;
    dbgSarasas: TcxGrid;
    dbgSarasasDBTableView: TcxGridDBTableView;
    dbgSarasasLevel1: TcxGridLevel;
    cxGroupBox1: TcxGroupBox;
    dbnNav: TcxDBNavigator;
    dbgSarasasDBTableViewilgis: TcxGridDBColumn;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure GmiImportasClick(Sender: TObject);
  private
    { Private declarations }
    m_arImportas: boolean;

    procedure LentelesOn;
    procedure LentelesOff;
    //
    procedure MainBeforeInserOrEdit(DataSet: TDataSet);
    procedure MainBeforePost(DataSet: TDataSet);
    procedure MainAfterPostOrDelete(DataSet: TDataSet);
    procedure MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
    procedure MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
    procedure MainNewRecord(DataSet: TDataSet);
  public
    { Public declarations }
    procedure RefreshTables; override;
  end;

var
  fMedIlgis: TfMedIlgis;

implementation

{$R *.dfm}

uses
  bendri, med_dm, Tools;

procedure TfMedIlgis.LentelesOn;
begin
  with dmMed do begin
    tbMedIlgis.BeforeInsert  := self.MainBeforeInserOrEdit;
    tbMedIlgis.BeforeEdit    := self.MainBeforeInserOrEdit;
    tbMedIlgis.BeforePost    := self.MainBeforePost;
    tbMedIlgis.AfterPost     := self.MainAfterPostOrDelete;
    tbMedIlgis.AfterDelete   := self.MainAfterPostOrDelete;
    tbMedIlgis.AfterCancel   := self.MainAfterPostOrDeleteOrCancel;
    //tbMedRastKub.OnPostError   := self.MainPostError;
    tbMedIlgis.OnNewRecord   := self.MainNewRecord;
  end;
end;

procedure TfMedIlgis.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  LentelesOff;
end;

procedure TfMedIlgis.FormShow(Sender: TObject);
begin
  inherited;
  LentelesOn;
end;

procedure TfMedIlgis.GmiImportasClick(Sender: TObject);
begin
  try
    LentelesOff;
    m_arImportas := true;
    fImpExp.DataSet := dmMed.tbMedIlgis;
    dmMed.tbMedIlgis.DisableControls;
    //fImpExp.BeforeStart := ImportBeforeStart;
    //fImpExp.AfterEnd := ImportAfterEnd;
    //dmVagonai.tbVStotys.OnNewRecord := self.StotysNewRecord;
    //fImpExp.BeforeInsert := ImportBeforeInsert;
    fImpExp.ImEx := importas;
    fImpExp.IniFileName := 'ismatavimai.ini';
    if fImpExp.ShowModal(DokTipas) <> mrYes then Exit;
  finally
    m_arImportas := false;
    dmBendras.ApplyUpdatesAfterPostOrDelete( dmMed.tbMedIlgis );
    dmMed.tbMedIlgis.Refresh;
    dmMed.tbMedIlgis.EnableControls;
    bRefreshTables := true;
    //dmVagonai.tbVVagonaiS.Refresh;
    LentelesOn;
  end;
end;

procedure TfMedIlgis.LentelesOff;
begin
  with dmMed do begin
    tbMedIlgis.BeforeInsert  := nil;
    tbMedIlgis.BeforeEdit    := nil;
    tbMedIlgis.BeforePost    := nil;
    tbMedIlgis.AfterPost     := nil;
    tbMedIlgis.AfterDelete   := nil;
    tbMedIlgis.AfterCancel   := nil;
    //tbMedRastKub.OnPostError   := nil;
    tbMedIlgis.OnNewRecord   := nil;
  end;
end;

procedure TfMedIlgis.MainBeforePost(DataSet: TDataSet);
begin
  //MessageText := '';
  //dmBendras.RandomIDBeforePost(DataSet);
end;

procedure TfMedIlgis.MainPostError(DataSet: TDataSet;
                E: EDatabaseError; var Action: TDataAction);
begin
  //dmBendras.RandomIDPostError(DataSet, E, Action);
end;

procedure TfMedIlgis.MainNewRecord(DataSet: TDataSet);
begin
  //
end;

procedure TfMedIlgis.MainAfterPostOrDelete(DataSet: TDataSet);
begin
  dmBendras.ApplyUpdatesAfterPostOrDelete(DataSet);
  MainAfterPostOrDeleteOrCancel(DataSet);
  bRefreshTables := true;
end;

procedure TfMedIlgis.MainAfterPostOrDeleteOrCancel(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, false );
end;

procedure TfMedIlgis.MainBeforeInserOrEdit(DataSet: TDataSet);
begin
  SetControlsEditColor( DataSet, GamaPageControl, true);
end;

procedure TfMedIlgis.RefreshTables;
begin
  if bRefreshTables then begin
    bRefreshTables := false;
    //dmAlga.tbIssilavLookup.Refresh;
  end
end;

end.
